import { setBrowseNumber } from "./base.js";
$("#header").load("./layout/header.html");

$("#footer").load("./layout/footer.html", function () {
	$("#accordionExample").on("hide.bs.collapse show.bs.collapse", function (e) {
		let target = e.target;
		let partens = "#" + $("#" + target.id).attr("aria-labelledby");
		$(partens).find("i").toggleClass("bi-chevron-down");
		$(partens).find("i").toggleClass("bi-chevron-up");
	});

	setBrowseNumber();
});

const init = function () {
	if (location.search) {
		let type = location.search.split("=")[1];
		$(`.${type}`).addClass("active");
		$(`#${type}`).show();
	} else {
		$(`.companyProfile`).addClass("active");
		$(`#companyProfile`).show();
	}

	$(function () {
		initHonorList("honor");
	});
};

init();

$(".tabbar_c .tabbar").click(function () {
	$(".tabbar_c .tabbar").removeClass("active");
	$(this).addClass("active");
	$(".container_c .container").hide();
	$(`#${$(this).data("key")}`).show();
});

$("#developmentProgram .list-group-item").click(function () {
	$("#developmentProgram .list-group-item").removeClass("active");
	$(this).addClass("active");
	$(".demonstrationPlot,.benefit,.interest,.overAllPlan").hide();
	$(`.${$(this).attr("data-type")}`).show();
	$("#developmentProgram .labelName").html($(this).text());
	$("#developmentProgramExample").collapse("hide");
});

$("#developmentHistory .layui-timeline-item").click(function () {
	$("#developmentHistory .layui-timeline-item").removeClass("active");
	$(this).addClass("active");
});

var mySwiper = new Swiper(".swiper", {
	autoplay: false, //可选选项，自动滑动
	lazy: {
		loadPrevNext: true
	},
	navigation: {
		nextEl: ".swiper-button-next",
		prevEl: ".swiper-button-prev"
	}
});

$("#enterpriseHonor .list-group-item").click(function () {
	$("#enterpriseHonor .list-group-item").removeClass("active");
	$(this).addClass("active");
	let type = $(this).attr("data-type");
	$("#enterpriseHonor .labelName").html($(this).text());
	$("#enterpriseHonorExample").collapse("hide");
	initHonorList(type);
});

// 渲染企业荣誉列表
const initHonorList = function (type) {
	let list;
	if (type == "honor") {
		list = 23;
	}else if(type == "aftersale") {
        list = 1;
    }else if(type == "food") {
        list = 5;
    }else if(type == "iso") {
        list = 6
    }else if(type =="patent") {
        list = 6
    }

	let str = "";
	for (let i = 1; i <= list; i++) {
		str += `
            <div class="swiper-slide text-center">
		        <img src="./src/images/${type}/${type}-${i}.jpg" class="swiper-lazy" style="width:50%"/>
                <div class="swiper-lazy-preloader"></div>
			</div>
        `;
	}

	$("#enterpriseHonor .swiper-wrapper").html(str);
};

// 发展规划类目选择
$("#developmentProgramExample").on(
	"hide.bs.collapse show.bs.collapse",
	function (e) {
		$("#developmentProgram .showBox").find("i").toggleClass("bi-chevron-down");
		$("#developmentProgram .showBox").find("i").toggleClass("bi-chevron-up");
	}
);

// 企业荣誉类目选择
$("#enterpriseHonorExample").on(
	"hide.bs.collapse show.bs.collapse",
	function (e) {
		$("#enterpriseHonor .showBox").find("i").toggleClass("bi-chevron-down");
		$("#enterpriseHonor .showBox").find("i").toggleClass("bi-chevron-up");
	}
);
